home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C++ / Frameworks / Sprocket Framework DR2 / Sprocket Nothing / SprocketNothing Code / SprocketNothing.cp < prev    next >
Encoding:
Text File  |  1996-06-15  |  5.4 KB  |  247 lines  |  [TEXT/CWIE]

  1. /*
  2.  
  3.     File:        SprocketNothing.cp
  4.     Project:    Sample code for Sprocket Framework 1.1 (DR2), released 6/15/96
  5.     Contains:    Boilerplate application-specific code
  6.     To Do:        Whatever your heart desires
  7.  
  8.     Sprocket Major Contributors:
  9.     ----------------------------
  10.     Dave Falkenburg, producer of Sprocket 1.0
  11.     Bill Hayden,     producer of Sprocket 1.1
  12.     Steve Sisak,     producer of the upcoming Sprocket 2.0
  13.     
  14.     Pete Alexander        Steve Falkenburg    Randy Thelen
  15.     Eric Berdahl        Nitin Ganatra        Chris K. Thomas
  16.     Marshall Clow        Dave Hershey        Leonard Rosenthal
  17.     Tim Craycroft        Dave Mark            Dean Yu
  18.     David denBoer        Gary Powell
  19.     Cameron Esfahani    Jon Summers            Apple Computer, Inc.
  20.         
  21.     Comments, Additions, or Corrections:
  22.     ------------------------------------
  23.     Bill Hayden, Nikol Software <nikol@codewell.com>
  24.  
  25. */
  26.  
  27.  
  28.  
  29. #include "Sprocket.h"
  30. #include "UDialog.h"
  31. #include "SplashWindow.h"
  32.  
  33. #include "EmptyWindow.h"
  34.  
  35. //    Function Prototypes:
  36.  
  37. void    AboutBox(void);
  38. void    OpenExistingDocument(void);
  39.  
  40. #define    kAboutBoxFor68K                    256
  41. #define    kAboutBoxForPowerPC                257
  42.  
  43.  
  44. ////////////////////////////////////////////////////////////////////
  45. //
  46. //    SetupApplication
  47. //
  48. //    Modify this function to provide any application-specific
  49. //    initialization you may require.
  50. //
  51. //    This is a good place to call EnterMovies, allocate
  52. //    sound channels, setup network things, etc.
  53. //
  54. //  For kicks, I am sercuring this application with Serial Number protection
  55.  
  56. OSErr SetupApplication(void)
  57. {
  58.     InitCursor();
  59.     
  60.     return noErr;
  61. }
  62.  
  63.  
  64.  
  65. ////////////////////////////////////////////////////////////////////
  66. //
  67. //    TearDownApplication
  68. //
  69. //    Modify this function to tear down anything that you allocated
  70. //    from within SetupApplication.
  71.  
  72. void TearDownApplication(void)
  73. {
  74. }
  75.  
  76.  
  77. ////////////////////////////////////////////////////////////////////
  78. //
  79. //    HandleMenuCommand
  80. //
  81. //    Modify this function to handle any registered menu commands
  82. //    that aren’t specific to a particular window.
  83.  
  84. void HandleCommand(CommandID theCommand)
  85. {
  86.     switch (theCommand)
  87.         {
  88.         case    cAbout:
  89.             AboutBox();
  90.             break;
  91.             
  92.         case    cNew:
  93.             CreateNewDocument();
  94.             break;
  95.             
  96.         case    cOpen:
  97.             OpenExistingDocument();
  98.             break;
  99.  
  100.         default:
  101.             break;
  102.         }
  103. }
  104.  
  105.  
  106. ////////////////////////////////////////////////////////////////////
  107. //
  108. //    HandleMenuSelection
  109. //
  110. //    Modify this function to handle any menu selections that aren’t
  111. //    specific to a particular window. Normally, you shouldn’t need to
  112. //    do anything, unless you hate using MenuCommands.
  113.  
  114. void HandleMenuSelection(MenuID /* theMenu */, MenuItemID /* theItem */)
  115. {
  116. }
  117.  
  118.  
  119. ////////////////////////////////////////////////////////////////////
  120. //
  121. //    ReadLocalClipboardFromScrap & WriteLocalClipboardToScrap
  122. //
  123. //    These functions will be called whenever the user switches into
  124. //    or out of your application.
  125. //
  126. //    If you keep copy of the clipboard in your own data structures,
  127. //    these functions will allow you to keep it in synch so that the
  128. //    user can cut and paste information between your program and
  129. //    other applications.
  130. //
  131. //    We don’t actually use the clipboard in SprocketSample, so these
  132. //    functions are empty for now.
  133.  
  134. void ReadLocalClipboardFromScrap(void)
  135. {
  136. }
  137.  
  138. void WriteLocalClipboardToScrap(void)
  139. {
  140. }
  141.  
  142.  
  143. ////////////////////////////////////////////////////////////////////
  144. //
  145. //    CreateNewDocument, OpenDocument, PrintDocument, and
  146. //    QuitApplication.
  147. //
  148. //    These functions will be called whenever one of the required
  149. //    AppleEvents is sent to your application— either when your
  150. //    program is launched, or when the user opens a document from
  151. //    the Finder.
  152.  
  153. OSErr CreateNewDocument(void)
  154. {
  155.     TEmptyWindow*    aWindow = new TEmptyWindow;
  156.     
  157.     if (aWindow == nil)
  158.         return nilHandleErr;
  159.     else
  160.         return noErr;
  161. }
  162.  
  163.  
  164. OSErr OpenDocument(FSSpec* theDocument, void * /*unused*/)
  165. {
  166.     // A normal app would open the document passed to this function
  167.     // This shell just opens a new document.
  168.     
  169.     return CreateNewDocument();
  170. }
  171.  
  172.  
  173. OSErr PrintDocument(FSSpec* /* theDocument */, void * /*unused*/)
  174. {
  175.     //    We don’t do printing yet, but you could.
  176.     return errAEEventNotHandled;
  177. }
  178.  
  179.  
  180. Boolean QuitApplication(void)
  181. {
  182.     //    Just go ahead and say we’re done quitting…
  183.     //    We have no app-specific clean-up or chores to do here, but you might.
  184.     
  185.     return true;
  186. }
  187.  
  188.  
  189.  
  190. ////////////////////////////////////////////////////////////////////
  191. //
  192. //    AboutBox
  193. //
  194. //    Put up our about box, including the version number. Depending
  195. //    on what version we are running, pick the correct DLOG resource.
  196. //
  197.  
  198. void AboutBox(void)
  199. {
  200.     Handle            versionHandle;
  201.     StringPtr        shortVersionString;
  202.     short            itemHit;
  203.  
  204.  
  205.     versionHandle = GetResource('vers', 1);
  206.     if (versionHandle)
  207.         {
  208.         shortVersionString = (StringPtr) ((char *) *versionHandle + 6);
  209.         ParamText(shortVersionString, "\p", "\p", "\p");
  210.         ReleaseResource(versionHandle);
  211.         }
  212.  
  213. #if GENERATING68K
  214.     itemHit = StandardAlert(kAboutBoxFor68K);
  215. #else
  216.     itemHit = StandardAlert(kAboutBoxForPowerPC);
  217. #endif
  218. }
  219.  
  220.  
  221.  
  222. ////////////////////////////////////////////////////////////////////
  223. //
  224. //    OpenExistingDocument
  225. //
  226. //    Use StandardFile to ask the user for a file to open. We use
  227. //    CustomGetFile so that we can properly handle update events
  228. //    in other windows while the dialog is active.
  229.  
  230. void OpenExistingDocument(void)
  231. {
  232.     StandardFileReply    reply;
  233.     SFTypeList            ourTypes;
  234.     
  235.     Point    where = { -1, -1 };
  236.     
  237.     HiliteWindowsForModalDialog(false);
  238.     CustomGetFile((FileFilterYDUPP) nil, -1, ourTypes, &reply, 0, where,
  239.                   (DlgHookYDUPP) nil, StandardDialogFilterYDUPP, nil, nil, nil);
  240.     HiliteWindowsForModalDialog(true);
  241.     
  242.     if (reply.sfGood)
  243.         {
  244.         OpenDocument(&reply.sfFile, nil);
  245.         }
  246. }
  247.